<template>
  <vxe-modal
    title="查看材料消耗详情"
    v-model="dialogVisible"
    :loading="loadings" height="85vh"
    width="70%" showFooter esc-closable show-zoom resize>
    <!-- 顶部搜索 -->
    <el-form :model="queryParams" ref="queryForm" size="small" v-show="showSearch" label-width="100px">
      <el-row :gutter="24">
        <el-col :span="8">
          <el-form-item label="年度:" prop="nd">
            <el-input
              v-model="queryParams.nd"
              placeholder="请输入年度"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="项目名称:" prop="xmName">
            <el-input
              v-model="queryParams.xmName"
              placeholder="请输入项目名称"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="项目编号:" prop="xmBh">
            <el-input
              v-model="queryParams.xmBh"
              placeholder="请输入项目编号"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="24">
        <el-col :span="8">
          <el-form-item label="记录开始时间:">
            <el-date-picker
              v-model="daterangeJlQTime"
              style="width: 100%"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="记录结束时间:">
            <el-date-picker
              v-model="daterangeJlZTime"
              style="width: 100%"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <!-- 表格 -->
    <el-table ref="table" highlight-current-row
              :header-cell-style="{background:'#d0cece',color:'#000000',fontWeight:'bold'}"
              v-loading="loading" :data="clxhtbList">
      <!--      <el-table-column type="selection" width="55" align="center"/>-->
      <el-table-column label="序号" align="center" type="index" :index="indexMethod"/>
      <el-table-column label="年度" align="center" prop="nd" width="60"/>
      <el-table-column label="项目名称" align="center" prop="xmName">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="handleButtonClick(scope.row)"
          >
            <el-link type="primary">{{ '(第' + scope.row.jlCs + '次)' + scope.row.xmName }}</el-link>
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="项目编号" align="center" prop="xmBh"/>
      <el-table-column label="记录开始时间" align="center" prop="jlQTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.jlQTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="记录结束时间" align="center" prop="jlZTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.jlZTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="记录次数" align="center" prop="jlCs"/>
      <el-table-column label="填报时间" align="center" prop="tbTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.tbTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="项目负责人" align="center" prop="xmFzName"/>
    </el-table>

    <!-- 分页组件 -->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 材料消耗填报详情 -->
    <ClXhTbXq ref="clXhTbXq"/>


  </vxe-modal>
</template>

<script>
import {listClxhtb} from "@/api/fztz/clxhtb";
import ClXhTbXq from "@/views/fztz/clxhtb/components/ClXhTbXq.vue";

export default {
  name: "ClXhCk", //材料消耗查看页面 (研发活动记录查看)
  components: {ClXhTbXq},
  dicts: ['fztz_clxhtb_yt'],
  data() {
    return {
      loadings: false,
      // 总条数
      total: 0,
      dialogVisible: false,
      loading: false,
      // 材料消耗填报表格数据
      clxhtbList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nd: null,
        xmsbId: null,
        xmName: null,
        xmBh: null,
        jlQTime: null,
        jlZTime: null,
        xmFzName: null,
        idWhere: null,
        userId: null,
        deptId: null
      },
      // 显示搜索条件
      showSearch: true,
      // 文件大小时间范围
      daterangeJlQTime: [],
      // 文件大小时间范围
      daterangeJlZTime: [],

    }
  },
  methods: {
    handleOpen(row) {
      this.xmsbId = row.xmsbId
      this.dialogVisible = true
      this.loadings = true
      this.getList()
    },
    /** 查询材料消耗填报列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      this.queryParams.xmsbId = this.xmsbId
      if (null != this.daterangeJlQTime && '' != this.daterangeJlQTime) {
        this.queryParams.params["beginJlQTime"] = this.daterangeJlQTime[0];
        this.queryParams.params["endJlQTime"] = this.daterangeJlQTime[1];
      }
      if (null != this.daterangeJlZTime && '' != this.daterangeJlZTime) {
        this.queryParams.params["beginJlZTime"] = this.daterangeJlZTime[0];
        this.queryParams.params["endJlZTime"] = this.daterangeJlZTime[1];
      }
      listClxhtb(this.queryParams).then(response => {
        this.clxhtbList = response.rows;
        this.total = response.total;
        this.loadings = false
        this.loading = false;
      });
    },
    //打开材料消耗填报详情组件
    handleButtonClick(row) {
      this.$refs.clXhTbXq.handleOpen(row)
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeJlQTime = [];
      this.daterangeJlZTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 自定义序号 */
    indexMethod(index) {
      let pageNum = this.queryParams.pageNum - 1;
      if ((pageNum !== -1 && pageNum !== 0)) {
        return (index + 1) + (pageNum * this.queryParams.pageSize);
      } else {
        return (index + 1)
      }
    },

  }
}
</script>

<style scoped>

</style>
